{block name="main"}
<!-- page -->
<form class="form-horizontal form-validate pt-15 widthFixedForm">

    <div class="form-group">
        <label class="col-md-2 control-label"><span class="text-bright">*</span>问题名称</label>
        <div class="col-md-5">
            <input type="text" class="form-control"  id="title" name="title" required value="{$questionDetail.title}">
        </div>
    </div>

    <div class="form-group">
        <label class="col-md-2 control-label"><span class="text-bright">*</span>问题分类</label>
        <div class="col-md-5">
            <select id="cate_id" name="cate_id" class="form-control" required>
                <option value="">请选择</option>
                {volist name="questionCateList['data']" id="vo"}
                {if $questionDetail.cate_id==$vo.cate_id}
                <option value="{$vo.cate_id}" selected>{$vo.name}</option>
                {else}
                <option value="{$vo.cate_id}" > {$vo.name}</option>
                {/if}
                {/volist}
            </select>
        </div>
    </div>
    <div class="form-group">
        <label class="col-md-2 control-label"><span class="text-bright">*</span>问题内容</label>
        <div class="col-md-9">
            <div id="UE-article-content" data-content='{$questionDetail.content}' required></div>
        </div>
    </div>
    <div class="form-group">
        <label class="col-md-2 control-label">排序</label>
        <div class="col-md-2">
            <input type="number" min="0" class="form-control" id="sort" name="sort" value="{$questionDetail.sort}">
        </div>
    </div>
    <div class="form-group">
        <label class="col-md-2 control-label">是否显示</label>
        <div class="col-md-2">
            <div class="switch-inline">
                <input type="checkbox" id="switch1" name="switch1" {if $questionDetail.status==1}checked{/if}>
                       <label for="switch1" class=""></label>
            </div>
        </div>
    </div>
    <input type="hidden" value="{$questionDetail.question_id}" id="question_id" name="question_id">
    <div class="form-group"></div>
    <div class="form-group">
        <label class="col-md-2 control-label"></label>
        <div class="col-md-8">
            <button class="btn btn-primary " type="submit">保存</button>
            <a href="javascript:history.go(-1);" class="btn btn-default">返回</a>
        </div>
    </div>

</form>

<!-- page end -->
{/block}
{block name="script"}
<script>
    require(['util'], function (util) {
        util.validate($('.form-validate'), function (form) {
            var question_id = $("#question_id").val();
            var title = $("#title").val();
            var cate_id = $("#cate_id").val();
            var sort = $("#sort").val();
            var status = 0;
            if ($("#switch1").is(":checked")) {
                status = 1;
            }
            var content = $('#UE-article-content').data('content');
            if (content) {
                $.ajax({
                    type: "post",
                    url: "{$updateQuestionUrl}",
                    data: {
                        'question_id': question_id,
                        'title': title,
                        'cate_id': cate_id,
                        'content': content,
                        'sort': sort,
                        'status': status
                    },
                    async: true,
                    success: function (data) {
                        if (data["code"] > 0) {
                            util.message(data["message"], 'success', "{:__URL('ADDONS_MAINquestionList')}");
                        } else {
                            util.message(data["message"], 'danger');
                        }
                    }

                });
            } else {
                util.message('请填写文章内容');
            }

        });
    });
</script>
{/block}
